<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>企业信息</title>
</head>
<body class="layui-layout-body">
    <div class="layui-body">
        <!-- 内容主体区域 -->
        <div class="body_right">
            <h4 class="nav_title">企业信息
            </h4>
            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
		        <ul class="layui-tab-title">
		            <li lay-id="INFO">企业信息</li>
		            <li lay-id="ROLE">系统权限</li>
		            <li class="layui-this">流程设置</li>
		        </ul>
		        <div class="layui-tab-content" >
		            <div class="layui-tab-item layui-show">
						 <form class="layui-form">
				            <input type="hidden" name="selectedIds" id="selectedIds">
				            <#if workflow??>
				            <input type="hidden" name="workflowId" id="${workflow.workflowId}">
				            </#if>
				            <div class="layui-form-item">
						    		<label class="layui-form-label">流程名称</label>
						        <div class="layui-input-inline">
						            <input type="text" name="name" value="<#if workflow??>${workflow.name}</#if>" lay-verify="name" autocomplete="off" placeholder="请输入流程名称" class="layui-input">
						        </div>
							</div>
							<div class="layui-form-item">
					            <label class="layui-form-label">审核类型</label>
					            <div class="layui-input-inline">
					                <select name="workflowType">
					                	<#if workflow??>
					                	 <option value="JOIN" <#if workflow.workflowType=='JOIN'>selected</#if>>联合审核</option>
					                     <option value="QUEUE" <#if workflow.workflowType=='QUEUE'>selected</#if>>顺序审核</option>
					                     <option value="SPECIAL" <#if workflow.workflowType=='SPECIAL'>selected</#if>>特批流程</option>
					                	<#else>
					                	 <option value="JOIN">联合审核</option>
					                     <option value="QUEUE">顺序审核</option>
					                     <option value="SPECIAL">特批流程</option>
					                	</#if>
					                	
					                </select>
					            </div>
					        </div>
				        	<div class="layui-form-item">
				        		<label class="layui-form-label">审核人员</label>
					            <div class="layui-input-block">
					              	<input type="hidden" id="selectedData" value='<#if workflow?? && settings??>${settingsDatas}</#if>'>
					              	<ul class="new_people" id="custosInfo" data="EDITMULTISELECT">
					              	
						                <li id="selected">
						                	<a href="javascript:openwinx('选择审核人','/staff/selected/index.htm','1000','600');"> 
						                    <div class="add_img bcground_999">+</div>
						                    </a>
						                </li>
						            </ul>
							    </div>
				        	</div>
				        	
				        	<div class="layui-form-item">
				        		<label class="layui-form-label"></label>
					            <div class="layui-input-inline">
					               <button class="layui-btn" lay-submit="" lay-filter="add">提交</button>
					            </div>
				        	</div>
						</form>
						 
						 
						  <table class="layui-table mytable" lay-even="" lay-skin="nob">
				               <thead>
					                <tr>
					                    <th>流程名称</th>
					                    <th>审核类型</th>
					                    <th>审核人</th>
					                    <th>状态</th>
					                    <th>创建时间</th>
					                    <th>操作</th>
					                </tr>
				                </thead>
				                <tbody>
					                <#if workflows?exists && workflows?size &gt; 0>
					                	<#list workflows as item>
							                <tr>
							                    <td>${item.name}</td>
							                    <td>${item.workflowType}</td>
							                    <td>
							                    		<#list item.settings as settings>
							                    		<#if settings_index gt 0>,</#if>
							                    		${settings.person.name}
							                    		</#list>
							                    </td>
							                    <td>${item.workflowStatus}</td>
							                    <td>${item.createTime?string('yyyy-MM-dd HH:mm:ss')}</td>
							                    <td class="allbox_a">
							                    		<a href="/company/workflow/update.htm?workflowId=${item.workflowId}" class="process">修改</a> 
							                    		<#if item.workflowStatus =='PENDING'>
							                    		| <a href="javascript:xconfirm('确认发布流程','/workflow/publish.htm',{workflowId:'${item.workflowId}'});" class="process">发布</a>
							                    		</#if>
							                    </td>
							                </tr>
					                	</#list>
					                <#else>
					                	<tr><td colspan="4">暂无数据</td></tr>
					                </#if>
				                </tbody>
				            </table>
						  <!------>
				          
					</div>
	            </div>
       </div>
    </div>
 </div>
  
     
     <script>
        //JavaScript代码区域
        layui.use(['element','form','layedit','laypage'], function(){
            var element = layui.element;
            var form = layui.form;
            var   layer = layui.layer;
            
            element.on('tab(docDemoTabBrief)', function(elem){
		  		var id = $(this).attr('lay-id');
		  		
		  		if(id == 'INFO'){
		  			location.href='/company/info.htm';
		  		}
		  		if(id == 'ROLE'){
		  		 	location.href='/company/role.htm';
		  		}
		   });
		   
		   form.on('submit(add)', function(data){
        		
        		var selectedData = $selectedData.val();
		        if(!selectedData){
		        	layer("请添加审核人");
		        	return false;
		        }
		        
		        var dataList = eval('(' + selectedData + ')'),settingStr="";
		        for(i=0;i<dataList.length;i++){
		        	if(i > 0 ){
	            		settingStr+=","
	            	}
		        	settingStr += dataList[i].id+"|"+(i+1);
		        	console.log(settingStr);
		        
		        }
            		
            	var field = data.field;
            	field.settingStr = settingStr;
            	
            	<#if workflow??>
            	var url="/company/workflow/modify.htm";
            	<#else>
            	var url="/company/workflow/create.htm";
            	</#if>
            		
            	$.ajax({
					type:"POST", 
					url:url,
					data:field,
					success:function(result) {
						if(result.code=='1'){
							layer.alert("增加成功", {icon: 6},function () {
				           // 获得frame索引
				            		location.href="/company/workflows.htm";
				       		});
						}else{
						 	layer.msg(result.msg);
						}
				 	} 
				});
           
                return false;
         	});
         	
         	
          
        });
        
        
       
        
       
        
        
        
        var nubList = new Array(), $selectedData = $("#selectedData");
        
        
        function leftMove(index){
        	var a = nubList[index];
        	nubList[index] = nubList[index-1]
        	nubList[index-1] =a;
        	$selectedData.val(JSON.stringify(nubList))
        	info();
        	
        }
        
        function rigthMove(index){
        	var a = nubList[index];
        	nubList[index] = nubList[index+1]
        	nubList[index+1] =a;
        	$selectedData.val(JSON.stringify(nubList))
        	info();
        }
        
        function del(index){
        	nubList.splice(index, 1);
        	$selectedData.val(JSON.stringify(nubList))
        	info();
        }
        
        function info(){
        	var selectedData = $selectedData.val();
        	console.log(selectedData);
	        if(selectedData){
	        	nubList = eval('(' + selectedData + ')');
	        }
        	
        	var items = new Array();
        	
        	if(nubList.length==1){
	        	items=items.concat(
	        		['<li class="person">',
	                    '<div class="header_top">',
	                        '<img src="'+nubList[0].portrait+'" alt="" class="vatol_img">',
	                    '</div>',
	                    '<p class="only_title">'+nubList[0].name+'</p>',
	                    '<i class="icon_close" onclick="del(0)">x</i>',
	                '</li>'
			        ]
			     )
        	}else if(nubList.length > 1){
        		for(var i=0;i<nubList.length;i++){
        			if(i==0){
        				items=items.concat(
			        		['<li class="person">',
			                    '<div class="header_top">',
			                        '<img src="'+nubList[i].portrait+'" alt="" class="vatol_img">',
			                        '<div class="row">',
			                            '<a href="javascript:rigthMove('+i+')">></a>',
			                        '</div>',
			                    '</div>',
			                    '<p class="only_title">'+nubList[i].name+'</p>',
			                    '<i class="icon_close" onclick="del('+i+')">x</i>',
			                '</li>'
					        ]
					     )
        			}else if(nubList.length-1 == i){
        				items=items.concat(
			        		['<li class="person">',
			                    '<div class="header_top">',
			                        '<img src="'+nubList[i].portrait+'" alt="" class="vatol_img">',
			                        '<div class="row">',
			                            '<a href="javascript:leftMove('+i+')"><</a>',
			                        '</div>',
			                    '</div>',
			                    '<p class="only_title">'+nubList[i].name+'</p>',
			                    '<i class="icon_close" onclick="del('+i+')">x</i>',
			                '</li>'
					        ]
					     )
        			
        			}else{
        				var portrait = nubList[i].portrait?nubList[i].portrait:'/asset/images/portrait.png';
        				items=items.concat(
			        		['<li class="person">',
			                    '<div class="header_top">',
			                        '<img src="'+portrait+'" alt="" class="vatol_img">',
			                        '<div class="row">',
			                            '<a href="javascript:leftMove('+i+')"><</a>&nbsp&nbsp <a href="javascript:rigthMove('+i+')">></a>',
			                        '</div>',
			                    '</div>',
			                    '<p class="only_title">'+nubList[i].name+'</p>',
			                    '<i class="icon_close" onclick="del('+i+')">x</i>',
			                '</li>'
					        ]
					     )
        			
        			}
        		
        		}
        	}
			$("#selected").prevAll().remove();
			$(items.join('')).insertBefore("#selected");
			
			
        }
        
        
        
        
         <#if workflow??> info();</#if>
        
        
    </script>  
     
     
</body>
</html>